/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.farent.solutions.plugins.stripes.hyperstripes.core;

import java.util.Scanner;

/**
 *
 * @author frenio
 */
public class PrettyBuilder
{
    private int indentLevel;
    private String indent;
    private final StringBuilder builder;
    public static String NEW_LINE = System.getProperty("line.separator");

    public PrettyBuilder() {
        this(new StringBuilder(), "  ");
    }

    public PrettyBuilder(StringBuilder builder) {
        this(builder, "  ");
    }

    public PrettyBuilder(StringBuilder builder, String indent) {
        this.builder = builder;
        this.indent = indent;
    }

    public void writeln(Object value) {
        writeIndent();
        builder.append(value.toString());
        builder.append(NEW_LINE);
    }

    public StringBuilder getBuilder() {
        return builder;
    }

    public void write(String text) {
        builder.append(text);
    }

    public void writeIndent() {
        for (int i = 0; i < indentLevel; i++) {
            builder.append(indent);
        }
    }

    public void incrementIndent() {
        ++indentLevel;
    }

    public void decrementIndent() {
        --indentLevel;
    }

    public int getIndentLevel() {
        return indentLevel;
    }

    public void setIndentLevel(int indentLevel) {
        this.indentLevel = indentLevel;
    }

    @Override
    public String toString() {
        builder.trimToSize();
        return builder.toString();
    }
}
